package com.lynn.salary.service.impl;

import java.util.List;
import java.util.Map;

import com.lynn.salary.entity.Accessory;
import com.lynn.salary.service.IAccessoryService;

public class AccessoryService extends BaseService implements IAccessoryService {

	public Accessory getByName(String name, Accessory accessory) throws Exception {
		StringBuffer sql = new StringBuffer("select id from "+accessory.tableName()+" where name=? and isdeleted=0 and tag like '%"+Accessory.PUBLISH+"%'");
		List<Map<String,Object>> data = dao.prepareExecuteSQL(sql.toString(), new Object[]{name});
		Accessory r = new Accessory();
		if(data != null && data.size() ==1) {
			r.setId((String)data.get(0).get("id"));
			return r;
		}
		return null;
	}
	/**
	 * 分页查询
	 */
	public List<Map<String, Object>> showPartAsseroy(int currentPage,
			int perPage) throws Exception {
		return dao.getPartList(Accessory.class, new String[]{"id, name, alterTime, description,creator"}, "isdeleted=0 and tag like'%"+Accessory.PUBLISH+"%' order by alterTime desc limit " + (currentPage - 1) * perPage + "," + perPage);
	}
	public long findAllAccessoryNumber() throws Exception {
		List<Map<String, Object>> list = dao.getPartList(Accessory.class, new String[]{"count(id) as total"}, "isdeleted=0 and tag like'%"+Accessory.PUBLISH+"%' order by alterTime desc");
		return (Long)list.get(0).get("total");
	}

}
